package com.newcapec.modules.health.controller;

import com.newcapec.common.utils.PageUtils;
import com.newcapec.common.utils.R;
import com.newcapec.modules.health.entity.CustomerEntity;
import com.newcapec.modules.health.service.CustomerService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 学校信息表
 *
 * @author steven
 * @email wangsen127@163.com
 * @date 2021-12-08 17:13:05
 */
@RestController
@RequestMapping("health/customer")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @RequiresPermissions("health:customer:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = customerService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 列表
     */
    @GetMapping("/lists")
    @RequiresPermissions("health:customer:list")
    public R listall(){
        List<CustomerEntity> list = customerService.list();

        return R.ok().put("list", list);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @RequiresPermissions("health:customer:info")
    public R info(@PathVariable("id") Long id){
		CustomerEntity customer = customerService.get(id);

        return R.ok().put("customer", customer);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @RequiresPermissions("health:customer:save")
    public R save(@RequestBody CustomerEntity customer){
		customerService.save(customer);

        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @RequiresPermissions("health:customer:update")
    public R update(@RequestBody CustomerEntity customer){
		customerService.updateById(customer);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @RequiresPermissions("health:customer:delete")
    public R delete(Long[] ids){
		customerService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
